package com.cn.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cn.domain.Product;
import com.cn.service.ProductService;
import com.cn.service.impl.ProductServiceImpl;


public class ToEditServlet extends BaseServlet {
	//ProductService ps = new ProductServiceImpl();
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			String id = request.getParameter("id");
			Product p = ps.getProductById(Integer.parseInt(id));
			request.setAttribute("p", p);
			request.getRequestDispatcher("/admin/products/edit.jsp").forward(request, response);
		} catch (NumberFormatException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		}
	}

}
